<?php


namespace app\common\validate;

use think\Validate;

class Admin extends Validate
{
    //全局验证规则
    protected $rule = [
      'admin_username|管理员用户名' => 'require|min:6|max:16',
      'admin_password|密码' => 'require|min:6|max:16',
      'conpass|确认密码' => 'require|confirm:admin_password',
      'oldpass|原密码' => 'require',
      'newpass|新密码' => 'require',
      'admin_nickname|昵称' => 'require',
      'admin_email|邮箱' => 'require|email|unique:admin',
      'code|验证码' => 'require',
      'verify|验证码' => 'require|captcha'
    ];
    protected $message = [
      'admin_username.require' => '请输入管理员用户名',
      'admin_username.min' => '管理员用户名长度为6-16位',
      'admin_username.max' => '管理员用户名长度为6-16位',
      'admin_password.min' => '管理员密码长度为6-16位',
      'admin_password.max' => '管理员密码长度为6-16位',
    ];

    //登录验证场景
    public function sceneLogin()
    {
        return $this->only(['admin_username','admin_password','verify']);
    }

    //注册验证场景
    public function sceneRegister()
    {
        return $this->only(['admin_username','admin_password','conpass','admin_nickname','admin_email'])->append('admin_username','unique:admin');
    }

    //重置密码验证场景
    public function sceneReset()
    {
        return $this->only(['code']);
    }

    //管理员添加验证场景
    public function sceneAdd()
    {
        return $this->only(['admin_username','admin_password','conpass','admin_nickname','admin_email'])->append('admin_username','unique:admin');
    }

    //管理员编辑验证场景
    public function sceneEdit()
    {
        return $this->only(['oldpass','newpass','admin_nickname']);
    }
}